﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Linq;

namespace NCAABasketballTournament
{
    public class Tournament
    {
        public Bracket MidWest = new Bracket() { Name = "MidWest" };
        public Bracket East = new Bracket() { Name = "East" };
        public Bracket South = new Bracket() { Name = "South" };
        public Bracket West = new Bracket() { Name = "West" };


        public Bracket Finals = new Bracket() { Name = "Finals" };

        public Team RunTournament(List<Team> oTeams)
        {
            List<Team> oWinners = new List<Team>();

            oWinners.Add( FillBracket(oTeams, MidWest, "M") );
            oWinners.Add( FillBracket(oTeams, West, "W") );

            oWinners.Add( FillBracket(oTeams, East, "E") );
            oWinners.Add( FillBracket(oTeams, South, "S") );

            return Finals.RunFinals(oWinners);
        }

        private Team FillBracket(List<Team> oTeams, Bracket oBracket, string sRegion)
        {
            var oList = (from oTeam in oTeams
                         where oTeam.Region == sRegion
                         orderby oTeam.Seed
                         select oTeam).ToList<Team>();

            return oBracket.RunBracket(oList);
        }


    }
}
